package main

import "fmt"

//import "go_study/model"



func main() {
	// 面向对象

	// 多态 通过接口来完成
	a := payment{
		paymentmethod: "alipay",
	}

	a.info()

	hahalog := &log{
		name: "小程序支付",
		content: "小程序支付日志内容",
		addtime: 0,
	}

	var _iowriteVaraible iowrite = "12121"
	//var _iowriteVaraible *iowrite
	hahalog.writelog(_iowriteVaraible)

	netlog := networkLog{
		log: log{
			name:    "小程序支付网络日志",
			content: "小程序支付网络日志内容",
			addtime: 0,
		},
	}
	netlog.writelog(_iowriteVaraible)

}
// 定义一个接口
type pay interface {
	topay()
	info()
}
// 定义一个结构体
type payment struct {
	paymentmethod string
}

func (this *payment)topay() {
	fmt.Printf("topay:%s", this.paymentmethod)
}
func (this *payment)info() {
	fmt.Printf("info:%s", this.paymentmethod)
}

// 自定义类型也可以实现接口
type readwrite string
type read interface {
	scan()
}

func (this *readwrite)scan() {
	fmt.Println("readwrite")
}

type write interface {
	ench()
	write()
}

// 整合实践案例
// 日志结构体
type log struct {
	name string
	content string
	addtime int64
}

func (this *log)writelog(_write iowrite) {
	fmt.Println(this.name + "-------" + this.content)
	_write.ench()
	_write.write()
}

type networkLog struct {
	log
}
type ioLog struct {
	log
}

type iowrite string
type netwrite string

// 实现write接口
func (this *iowrite)ench() {
	fmt.Println("iowrite + ench")
}

func (this *iowrite)write() {
	fmt.Println("iowrite + write")
}

func (this *netwrite)ench() {
	fmt.Println("netwrite + ench")
}

func (this *netwrite)write() {
	fmt.Println("netwrite + write")
}